#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	char buff[1<<21],*p1=buff,*p2=buff;
	char getch(){return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;}
	template<typename T>void read(T &x){char ch=getch();int fl=1;x=0;while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}x*=fl;}
	template<typename T>void read_s(T &x){char ch=getch();while(ch<'a'||ch>'z')ch=getch();while(ch>='a'&&ch<='z'){x+=ch;ch=getch();}}
	template<typename T,typename ...Args>void read(T &x,Args& ...args){read(x);read(args...);}
	char obuf[1<<21],*p3=obuf;
	void putch(char ch) {if(p3-obuf<(1<<21))*p3++=ch;else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;}
	char ch[100];
	template<typename T>void write(T x) {if(!x)return putch('0');if(x<0)putch('-'),x*=-1;int top=0;while(x)ch[++top]=x%10+48,x/=10;while(top)putch(ch[top]),top--;}
	template<typename T,typename ...Args>void write(T x,Args ...args) {write(x);write(args...);}
	void put(string s){for(int i=0;i<s.size();i++)putch(s[i]);}
	void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
int n,m,q;
int c[100005];
int w[100005][6];
int sum[100005][6];
struct matrix
{
	int a[7][7];
	inline matrix operator*(const matrix &x)const
	{
		matrix res;memset(res.a,-0x3f,sizeof res.a);
		for(int i=1;i<=m+1;i++)
			for(int j=1;j<=m+1;j++)
				for(int k=1;k<=m+1;k++) res.a[i][j]=max(res.a[i][j],a[i][k]+x.a[k][j]);
		return res;
	}
	inline void init(int x)
	{
		matrix b1,b2;
		memset(b1.a,-0x3f,sizeof b1.a);
		memset(b2.a,-0x3f,sizeof b2.a);
		int s=sum[x][c[x]];
		for(int i=1;i<=m;i++) b1.a[i][i]=0;b1.a[c[x]][m+1]=s;b1.a[m+1][m+1]=w[x][c[x]];
		for(int i=1;i<=m+1;i++) b2.a[i][i]=0;
		b2.a[m+1][c[x]]=-s;
		b1=b1*b2;
		for(int i=1;i<=m+1;i++)
			for(int j=1;j<=m+1;j++) a[i][j]=b1.a[i][j];
	}
};
namespace Nene
{
	matrix t[100005<<2];
	#define ls (root<<1)
	#define rs (root<<1|1)
	#define mid (l+r>>1)
	void bld(int root=1,int l=1,int r=n)
	{
		if(l==r) return t[root].init(l),void();
		bld(ls,l,mid);bld(rs,mid+1,r);
		t[root]=t[ls]*t[rs];
	}
	void change(int x,int root=1,int l=1,int r=n)
	{
		if(l==r) return t[root].init(l),void();
		if(x<=mid) change(x,ls,l,mid);
		else change(x,rs,mid+1,r);
		t[root]=t[ls]*t[rs];
	}
	matrix query(int x,int y,int root=1,int l=1,int r=n)
	{
		if(l>=x&&r<=y) return t[root];
		if(y<=mid) return query(x,y,ls,l,mid);
		if(x>mid) return query(x,y,rs,mid+1,r);
		return query(x,y,ls,l,mid)*query(x,y,rs,mid+1,r);
	}
}using namespace Nene;
signed main()
{
	freopen("paint.in","r",stdin);
	freopen("paint.out","w",stdout);
	read(n,m,q);
	for(int i=1;i<=n;i++) read(c[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) read(w[i][j]),sum[i][j]=sum[i-1][j]+w[i][j];
	bld();
	int lastans=-114514;
	++q;
	while(q--)
	{
		int op,x,y;
		if(lastans!=-114514) read(op,x,y),x^=lastans,y^=lastans;
		else op=2,x=1,y=n;
		if(op==1) c[x]=y,change(x);
		else
		{
			matrix res=query(x,y);
			matrix tmp;memset(tmp.a,-0x3f,sizeof tmp.a);
			tmp.a[1][c[x]]=-sum[x-1][c[x]];tmp.a[1][m+1]=0;
			tmp=tmp*res;
			write(lastans=tmp.a[1][m+1]),putch('\n');
		}
	}
	flush();
	return 0;
}
/*
6095865
*/
